//
//  ViewController.swift
//  1.11.Grouping Compact Options with UISegmentedControl
//
//  Created by joker on 15/7/21.
//  Copyright (c) 2015年 joker. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var segmentedControl: UISegmentedControl!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
//        let segments = [
//        "iPhone",
//            "iPad",
//            "iPod",
//            "iMac"
//        ]
        
        let segments = NSArray(objects: "Red", UIImage(named: "BlueDot")!,"Green","Yellow")
        
        segmentedControl = UISegmentedControl(items: segments as [AnyObject])
        segmentedControl.center = view.center
//        segmentedControl.addTarget(self, action: "segmentedControllerChanged:", forControlEvents: .ValueChanged)
//        segmentedControl.momentary = true
        view.addSubview(segmentedControl)
    }
    func segmentedControllerChanged(segmentedController: UISegmentedControl) {
        
        let selectedSegmentIndex = segmentedControl.selectedSegmentIndex
        let selectedSegmentText = segmentedControl.titleForSegmentAtIndex(selectedSegmentIndex)
        println("Segment \(selectedSegmentIndex) with text " + "of \(selectedSegmentText!) is selected")
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

